from elua import dic_to_lua_str
from parse import parse_file, layout
from pathlib import Path
import os

def encode(ipath, opath):
	data = parse_file(ipath)
	data = layout(data)
	with open(opath, "w") as f:
		f.write("return "+ dic_to_lua_str(data))

if __name__ == '__main__':
	os.chdir("..")
	SRC = "./"
	DEST = "../static_layouts/"
	for path in Path(SRC).iterdir():
		if path.suffix == ".map":
			print("Convert: " + path.name)
			print("*********************")
			encode(path, Path(DEST) / ("rg_" + path.with_suffix(".lua").name))
			print()